﻿using System;
using RentalSystem.Data.EF.Core;
using System.Web.Security;
using RentalSystem.Data.EF;
using Web.Context;
using Web.Models;

namespace Web.Security
{
    public class SecurityManager
    {
        protected IDataContext dataContext;

        public SecurityManager()
        {
            this.dataContext = CurrentContext.Context.DataContext;
        }

        public void LoginUser(Users modelUser)
        {
            if (modelUser == null)
                throw new ArgumentNullException("Nieprawidłowy login lub hasło. Podanego użytkownika nie ma w bazie!");

            //TODO: check other informations about login restrictions - for example IP, permission list etc.

            User user = new User(modelUser);

            FormsAuthentication.SetAuthCookie(user.Email, false);
            CurrentContext.Context.CurrentUser = user;
        }
    }
}